﻿@{
    Layout = "_layout";
}
@{
    ViewData["Title"] = "添加产品";
    var Type = ViewBag.Type as List<BuyWithoutLoseMoney.Core.Models.ProductType>;
    var Pic = ViewBag.Pic as List<BuyWithoutLoseMoney.Core.Models.ProductPic>;
    var Pro = ViewBag.Pro as List<BuyWithoutLoseMoney.Core.Models.Product>;
}
@model BuyWithoutLoseMoney.Core.Models.Product;
<div>
    <div class="layui-card">
        <div class="layui-card-header">添加产品</div>
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">产品标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="Title" required lay-verify="required" placeholder="请输入产品标题" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">产品副标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="SubTitle" required lay-verify="required" placeholder="请输入产品副标题" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">单价</label>
                    <div class="layui-input-block">
                        <input type="text" name="Price" required lay-verify="required" placeholder="请输入单价" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">上架时间</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="CreateTime" id="ID-laydate-type-datetime1" placeholder="请选择上架时间">
                    </div>
                </div>、
                <div class="layui-form-item">
                    <label class="layui-form-label">下架时间</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="DelTime" id="ID-laydate-type-datetime2" placeholder="请选择下架时间">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="Status" value="1" title="上架" checked>
                        <input type="radio" name="Status" value="2" title="下架">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">品牌</label>
                    <div class="layui-input-block">
                        <input type="text" name="Brand" required lay-verify="required" placeholder="请输入品牌" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea name="Describe" placeholder="请输入描述" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">产品分类</label>
                    <div class="layui-input-block">
                        <select name="ProductTypeId" lay-verify="required">
                            @foreach (var item in Type)
                            {
                                <option value="@item.Id">@item.FirstTypeName</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="addForm">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@section Scripts{
    <script>
        layui.use(["form", 'layer', 'laydate'], function() {
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#ID-laydate-type-datetime1',
                type: 'datetime'
            });
            laydate.render({
                elem: '#ID-laydate-type-datetime2',
                type: 'datetime'
            });
            //提交
            form.on('submit(addForm)', function(data) {
                $.post("/admin/product/create", data.field, function(res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, function() {
                            parent.window.location.href = "/admin/product/index";
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                });
                return false;
            });
        })
    </script>
}